<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
	<meta name="theme-color" content="#33474d">
	<title>cacti的错误 | 失落的乐章</title>
	<link rel="stylesheet" href="/css/style.css" />
	
      <link rel="alternate" href="/atom.xml" title="失落的乐章" type="application/atom+xml">
    
</head>

<body>

	<header class="header">
		<nav class="header__nav">
			
				<a href="/archives" class="header__link">Archive</a>
			
				<a href="/tags" class="header__link">Tags</a>
			
				<a href="/atom.xml" class="header__link">RSS</a>
			
		</nav>
		<h1 class="header__title"><a href="/">失落的乐章</a></h1>
		<h2 class="header__subtitle">技术面前，永远都是学生。</h2>
	</header>

	<main>
		<article>
	
		<h1>cacti的错误</h1>
	
	<div class="article__infos">
		<span class="article__date">2017-10-12</span><br />
		
		
			<span class="article__tags">
			  	<a class="article__tag-link" href="/tags/Cacti/">Cacti</a>
			</span>
		
	</div>

	

	
		<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">FATAL: Cannot connect to MySQL server on <span class="string">'localhost'</span>. Please make sure you have specified a valid MySQL database name <span class="keyword">in</span> <span class="string">'include/config.php'</span></div></pre></td></tr></table></figure>
<h2 id="1-查看config-php下，是否配置正确"><a href="#1-查看config-php下，是否配置正确" class="headerlink" title="1.查看config.php下，是否配置正确"></a>1.查看config.php下，是否配置正确</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看cactiusr的host是否有localhost 权限</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">mysql -ucactiuser -h localhost -p</div></pre></td></tr></table></figure>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;查看登录是否成功 ，如果登录正常则排除</p>
<h2 id="2-MYSQL权限问题"><a href="#2-MYSQL权限问题" class="headerlink" title="2.MYSQL权限问题"></a>2.MYSQL权限问题</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">SQL&gt;GRANT ALL ON cacti.* TO cactiuser@localhost IDENTIFIED BY <span class="string">'somepassword'</span>;</div></pre></td></tr></table></figure>
<h2 id="3-当mysql中的所有配置和cacti的config-php都正确，却还是出现该错误时，那就是mysql套接字的原因了"><a href="#3-当mysql中的所有配置和cacti的config-php都正确，却还是出现该错误时，那就是mysql套接字的原因了" class="headerlink" title="3.当mysql中的所有配置和cacti的config.php都正确，却还是出现该错误时，那就是mysql套接字的原因了~"></a>3.当mysql中的所有配置和cacti的config.php都正确，却还是出现该错误时，那就是mysql套接字的原因了~</h2><p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;cacti会自动的去查找/var/lib/mysql/mysql.sock 该套接字，但是如果是源码安装的mysql，未指定套接字位置时，套接字的位置为/tmp/mysql.sock，由于cacti未找到/var/lib/mysql/mysql.sock，所以显示的是“Cannot connect to MySQL server on ‘localhost’”</p>
<p>&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;解决：做一个/tmp/mysql.sock到/var/lib/mysql/mysql.sock的软连接</p>
<figure class="highlight bash"><table><tr><td class="gutter"><pre><div class="line">1</div></pre></td><td class="code"><pre><div class="line">ln -s  /tmp/mysql.sock  /var/lib/mysql/mysql.sock</div></pre></td></tr></table></figure>

	

	
		<span class="different-posts"><a href="/2017/10/12/Cacti/3. cacti 的错误/" onclick="window.history.go(-1); return false;">⬅️ Go back </a></span>

	

</article>

	</main>

	<footer class="footer">
	<div class="footer-content">
		
	      <div class="footer__element">
	<p>Hi there, <br />welcome to my Blog glad you found it. Have a look around, will you?</p>
</div>

	    
	      <div class="footer__element">
	<h5>Check out</h5>
	<ul class="footer-links">
		<li class="footer-links__link"><a href="/archives">Archive</a></li>
		
		  <li class="footer-links__link"><a href="/atom.xml">RSS</a></li>
	    
		<li class="footer-links__link"><a href="/about">about page</a></li>
		<li class="footer-links__link"><a href="/tags">Tags</a></li>
		<li class="footer-links__link"><a href="/categories">Categories</a></li>
	</ul>
</div>

	    

		<div class="footer-credit">
			<span>© 2017 失落的乐章 | Powered by <a href="https://hexo.io/">Hexo</a> | Theme <a href="https://github.com/HoverBaum/meilidu-hexo">MeiliDu</a></span>
		</div>

	</div>


</footer>



</body>

</html>
